<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<link href="houtai/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="houtai/js/main.js"></script>
<script type="text/javascript">
var xmlhttp;
function ckmenname(){

	var menname=document.getElementById("menname").value;
	if(menname==""){
		document.getElementById("spnmname").innerHTML="请输入菜单名";
		document.getElementById("spnmname").style.color="red";
		return false;
	}
	document.getElementById("spnmname").innerHTML="";
	xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange=ckmname;
	
	xmlhttp.open("get", "MenuServlet?param=ajaxmenuname&menname="+menname+"&time="+new Date().getTime(), true);
	xmlhttp.send(null);
}
function ckmname(){
	if(xmlhttp.readyState==4 && xmlhttp.status==200){
		document.getElementById("spnmname").innerHTML=xmlhttp.responseText;
	}
}

function ckname(){
	if(document.getElementById("menname").value==""){
		document.getElementById("spnmname").innerHTML="请输入菜单名";
		document.getElementById("spnmname").style.color="red";
		return false;
	}
	document.getElementById("spnmname").innerHTML="";
	return true;
}
function ckmenurl(){
	var menurl=document.getElementById("menurl").value;
	if(menurl==""){
		document.getElementById("s1").innerHTML="请输入url路径";
		document.getElementById("s1").style.color="red";
		return false;
	}
	document.getElementById("s1").innerHTML="";

	return true;
	
	
}
	
function ckspan(){
	var spn=document.getElementById("spnmname").innerHTML;
	if(spn=="菜单名已存在"){
		alert("菜单名已存在");
		return false;
	}
	return true;
	
}


function ckremark(){
	if(document.getElementById("menremark").value==""){
		document.getElementById("s11").innerHTML="备注不能为空";
		document.getElementById("s11").style.color="red";
		return false;
	}
	document.getElementById("s11").innerHTML="";
	return true;
}


	function check() {
		if (ckspan()&&ckname()) {
			
			if(document.getElementById("fmend").value!=-1){
			
				if(ckmenurl()){
					if (confirm("确定保存吗？")) {
						document.getElementById("form1").submit();
						return true;
					}
				}else{
					return false;
				}
				
			}else{
				if (confirm("确定保存吗？")) {
					document.getElementById("form1").submit();
					return true;
				} 
			}
			
		}
		return false;
		
	}

	
	function changeurl(v){
		if(v.value!=-1){
			document.getElementById("urlid").style.display="";
			
		}else{
			document.getElementById("urlid").style.display="none";
			
		}
	}
</script>
</head>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td style="height:25px; background-color:#f3f3f3; font-weight:bold" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;当前位置：
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda创业教育平台&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;后台管理&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;菜单管理
    </td>
  </tr>
  <tr>
    <td style="height:34px; background-image:url(houtai/images/main_header.gif); border-bottom:1px solid #cfd8e0; padding:0px">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="20" height="34"><img src="houtai/images/main_headerL.gif" width="20" height="34"></td>
          <td style="color:#90c8e8;"><img src="houtai/images/icon_card.gif" width="16" height="16" align="absmiddle">&nbsp;&nbsp;<strong>添加菜单</strong></td>
          <td align="right" class="white" style="padding-right:20px">
          <a  class="barBtn" onClick="javascript:history.go(-1);"><img src="houtai/images/btn_left.gif" align="absmiddle"> 后退</a>
          <a  class="barBtn" onClick="javascript:history.go(+1);"><img src="houtai/images/btn_right.gif" align="absmiddle"> 前进</a>
          <a href="javascript:history.go(0);" class="barBtn"><img src="houtai/images/btn_refresh.gif" align="absmiddle"> 刷新</a>
          </td>
        </tr>
    </table></td>
  </tr>
  <tr>
   <form id="form1" action="<%=request.getContextPath() %>/MenuServlet?param=addMenuInfo" method="post">
    <td height="100%" valign="top">
    <div style="overflow:auto;height:100%; width:100%">
      <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
        <TR>
          <th width="20%" align="center" >菜单名</th>
          <TD class="BGCgray"><input type="text" name="menname" id="menname" onblur="ckmenname()" /><span id="spnmname"></span></TD>
        </TR>
        <TR>
          <th width="20%" align="center">父级菜单</th>
          <TD class="BGCgray">
          	<select name="fmenid" onclick="changeurl(this)" id="fmend">
            <option value="-1">顶级菜单</option>
           <c:forEach items="${requestScope.fmenus }" var="fmenu">
           		<option value="${fmenu.fmeId }">${fmenu.fmeName }</option>
           </c:forEach>
            </select>
          </TD>
        </TR>
        
        
        <TR id="urlid" style="display: none;">
          <th align="center">url路径</th>
          <TD class="BGCgray">
			<input type="text" name="menurl"  id="menurl" onblur="ckmenurl()"/><span id="s1"></span>
          </TD>
        </TR>
        
        
        
        <TR>
          <th align="center">启用状态</th>
          <TD class="BGCgray">
          <input type="radio" value="1" name="menstate" checked="checked" />启用
          <input type="radio" value="0" name="menstate"/>禁用
          </TD>
        </TR>
        <TR>
          <th align="center"><span class="BGCgray">备注</span></th>
          <TD class="BGCgray">
          	<textarea name="menremark" id="menremark" onblur="ckremark()" >暂无
            </textarea><span id="s11"></span>
          </TD>
        </TR>
      </table>
      <div style="width:100%; text-align:center; padding:5px">
        <BUTTON style="HEIGHT:25px" onclick="return check()"><img src="houtai/images/btn_save.gif" width="16" height="16" align="absmiddle"> 保存</BUTTON><BUTTON style="HEIGHT:25px" onClick="history.go(-1);"><img src="houtai/images/btn_back.gif" width="16" height="16" align="absmiddle"> 返回</BUTTON>
      </div>
    </div>
  </td>
  </tr>
 </form>
</table>
</body>
</html>